home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / think / AmigaGnuChess.lha / chess / src.lha / src / amiga / display.c < prev    next >
C/C++ Source or Header  |  1992-09-07  |  6KB  |  212 lines

  1. /*
  2.  *  Source generated with GadToolsBox V1.3
  3.  *  which is (c) Copyright 1991,92 Jaba Development
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/classes.h>
  9. #include <intuition/classusr.h>
  10. #include <intuition/imageclass.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfxbase.h>
  15. #include <proto/exec.h>
  16. #include <proto/intuition.h>
  17. #include <proto/gadtools.h>
  18. #include <proto/graphics.h>
  19. #include <string.h>
  20.  
  21. #include "display.h"
  22.  
  23. #define SCR_WIDTH    640
  24. #define SCR_HEIGHT    200
  25.  
  26. struct Screen        *Scr = NULL;
  27. APTR                  VisualInfo = NULL;
  28. struct Window        *ChessWnd = NULL;
  29. struct Menu          *ChessMenus = NULL;
  30. UWORD                 ChessLeft = 0;
  31. UWORD                 ChessTop = 0;
  32. UWORD                 ChessWidth = SCR_WIDTH;
  33. UWORD                 ChessHeight = SCR_HEIGHT;
  34. UBYTE                *ChessWdt = NULL;
  35.  
  36. struct TextAttr topaz8 = {
  37.     ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
  38.  
  39.  
  40. struct NewMenu ChessNewMenu[] = {
  41.     NM_TITLE, (STRPTR)"Project", NULL, 0, 0L, NULL,
  42.     NM_ITEM, (STRPTR)"New game", (STRPTR)"N", 0, 0L, NULL,
  43.     NM_ITEM, (STRPTR)"Load game...", (STRPTR)"L", 0, 0L, NULL,
  44.     NM_ITEM, (STRPTR)"Save game...", (STRPTR)"S", 0, 0L, NULL,
  45.     NM_ITEM, (STRPTR)"Create listing", NULL, 0, 0L, NULL,
  46.     NM_ITEM, (STRPTR)"Edit board", (STRPTR)"E", 0, 0L, NULL,
  47.     NM_ITEM, (STRPTR)"Help...", "?", 0, 0L, NULL,
  48.     NM_ITEM, (STRPTR)"About...", (STRPTR)"A", 0, 0L, NULL,
  49.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  50.     NM_TITLE, (STRPTR)"Settings", NULL, 0, 0L, NULL,
  51.     NM_ITEM, (STRPTR)"Select level", NULL, 0, 0L, NULL,
  52.     NM_ITEM, (STRPTR)"Change colors", NULL, 0, 0L, NULL,
  53.     NM_ITEM, (STRPTR)"Save colors", NULL, 0, 0L, NULL,
  54.     NM_TITLE,(STRPTR)"Toggles", NULL, 0, 0L, NULL,
  55.     NM_ITEM, (STRPTR)"Reverse board", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,
  56.     NM_ITEM, (STRPTR)"Coordinates", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,
  57.     NM_ITEM, (STRPTR)"Show thinking", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,
  58.     NM_ITEM, (STRPTR)"Random play", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,
  59.     NM_ITEM, (STRPTR)"Beep after move", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,
  60. /*    NM_ITEM, (STRPTR)"Use opening book", NULL, CHECKIT|MENUTOGGLE, 0L, NULL,*/
  61.     NM_TITLE,(STRPTR)"Move", NULL, 0, 0L, NULL,
  62.     NM_ITEM, (STRPTR)"Go!", (STRPTR)"G", 0, 0L, NULL,
  63.     NM_ITEM, (STRPTR)"Undo half-move", (STRPTR)"U", 0, 0L, NULL,
  64.     NM_ITEM, (STRPTR)"Undo whole-move", NULL, 0, 0L, NULL,
  65.     NM_ITEM, (STRPTR)"Switch sides", NULL, 0, 0L, NULL,
  66.     NM_ITEM, (STRPTR)"Input both sides", NULL, 0, 0L, NULL,
  67.     NM_ITEM, (STRPTR)"Redraw board", (STRPTR)"R", 0, 0L, NULL,
  68.     NM_ITEM, (STRPTR)"Hint", (STRPTR)"H", 0, 0L, NULL,
  69.     NM_END, NULL, NULL, 0, 0L, NULL };
  70.  
  71. struct ColorSpec  ScreenColors[] = {
  72.      0, 0x0B, 0x0A, 0x09,
  73.      1, 0x09, 0x07, 0x03,
  74.      2, 0x0E, 0x0C, 0x09,
  75.      3, 0x00, 0x00, 0x00,
  76.      4, 0x08, 0x0B, 0x05,
  77.      5, 0x0E, 0x0E, 0x0C,
  78.      6, 0x00, 0x06, 0x07,
  79.      7, 0x0B, 0x05, 0x07,
  80.     ~0, 0x00, 0x00, 0x00 };
  81.  
  82. UWORD             DriPens[] = {
  83.     0,3,1,5,3,7,3,0,7,~0 };
  84.  
  85. void LoadColors(char *name)
  86. {
  87.     FILE *f;
  88.     UWORD i;
  89.     int r, g, b;
  90.  
  91.     if (f = fopen(name, "r"))
  92.     {
  93.         for (i = 0; i < 8; i++)
  94.             if (fscanf(f, "%x %x %x", &r, &g, &b) == 3)
  95.             {
  96.                 ScreenColors[i].Red = r;
  97.                 ScreenColors[i].Green = g;
  98.                 ScreenColors[i].Blue = b;
  99.             }
  100.             else break;
  101.  
  102.         fclose(f);
  103.     }
  104. }
  105.  
  106. BOOL SaveColors(char *name)
  107. {
  108.     FILE *fp;
  109.     struct ColorMap *cm;
  110.     LONG colorval;
  111.     UWORD i, r,g,b;
  112.  
  113.     if (fp = fopen(name, "w"))
  114.     {
  115.         cm = Scr->ViewPort.ColorMap;
  116.         for (i = 0; i < 8; i++)
  117.         {
  118.             colorval = GetRGB4(cm, i);
  119.             r = colorval >> 8;
  120.             g = colorval >> 4 & 0xF;
  121.             b = colorval & 0xF;
  122.             fprintf(fp, "0x%x 0x%x 0x%x\n", r, g, b);
  123.         }
  124.         fclose(fp);
  125.         return TRUE;
  126.     }
  127.     return FALSE;
  128. }
  129.  
  130. int SetupScreen( void )
  131. {
  132.     if ( ! ( Scr = OpenScreenTags( NULL,  SA_Left,          0,
  133.                                           SA_Top,           0,
  134.                                           SA_Width,         SCR_WIDTH,
  135.                                           SA_Height,        SCR_HEIGHT,
  136.                                           SA_Depth,         3,
  137.                                           SA_Colors,        &ScreenColors[0],
  138.                                           SA_Font,          &topaz8,
  139.                                           SA_Type,          CUSTOMSCREEN,
  140.                                           SA_DisplayID,     HIRES_KEY,
  141.                                           SA_Pens,          &DriPens[0],
  142.                                           SA_Title,        
  143. "Amiga GnuChess v1.0  (c) 1986-92 F.S.F, 1992 M.W.Scott",
  144.                       SA_ShowTitle,        TRUE,
  145.                                           TAG_DONE )))
  146.         return( 1L );
  147.  
  148.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  149.         return( 2L );
  150.  
  151.     return( 0L );
  152. }
  153.  
  154. void CloseDownScreen( void )
  155. {
  156.     if ( VisualInfo ) {
  157.         FreeVisualInfo( VisualInfo );
  158.         VisualInfo = NULL;
  159.     }
  160.  
  161.     if ( Scr        ) {
  162.         CloseScreen( Scr );
  163.         Scr = NULL;
  164.     }
  165. }
  166.  
  167. int OpenChessWindow( void )
  168. {
  169.     struct NewGadget     ng;
  170.     struct Gadget       *g;
  171.     UWORD               offx, offy;
  172.  
  173.     offx = Scr->WBorLeft;
  174.     offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  175.  
  176.     if ( ! ( ChessMenus = CreateMenus( ChessNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  177.         return( 3L );
  178.  
  179.     LayoutMenus( ChessMenus, VisualInfo, GTMN_TextAttr, &topaz8, TAG_DONE );
  180.  
  181.     if ( ! ( ChessWnd = OpenWindowTags( NULL,
  182.                     WA_Left,          ChessLeft,
  183.                     WA_Top,           ChessTop = offy,
  184.                     WA_Width,         ChessWidth,
  185.                     WA_Height,        ChessHeight - offy,
  186.                     WA_Flags,         WFLG_ACTIVATE|WFLG_SMART_REFRESH|WFLG_BORDERLESS,
  187.                     WA_Title,         ChessWdt,
  188.             WA_IDCMP,          IDCMP_VANILLAKEY,
  189.                     WA_CustomScreen,  Scr,
  190.                     TAG_DONE )))
  191.         return( 4L );
  192.  
  193. /*    SetMenuStrip( ChessWnd, ChessMenus );*/
  194.     GT_RefreshWindow( ChessWnd, NULL );
  195.  
  196.     return( 0L );
  197. }
  198.  
  199. void CloseChessWindow( void )
  200. {
  201.     if ( ChessMenus      ) {
  202.         ClearMenuStrip( ChessWnd );
  203.         FreeMenus( ChessMenus );
  204.         ChessMenus = NULL;    }
  205.  
  206.     if ( ChessWnd        ) {
  207.         CloseWindow( ChessWnd );
  208.         ChessWnd = NULL;
  209.     }
  210. }
  211.  
  212.